import { loginApi, captchaloginApi } from '@/api/user.js'
import { setLocalStroage, getLocalStroage, KEY } from '@/utils/stroage'
export default {
  namespaced: true,
  state: {
    token: getLocalStroage(KEY) || ''
  },
  getters: {
  },
  mutations: {
    updataToken (state, payload) {
      state.token = payload
      setLocalStroage(KEY, payload)
    },
    updataToken2 (state, payload) {
      state.token = payload
      setLocalStroage(KEY, payload)
    }
  },
  actions: {
    async getToken (ctx, data) {
      const res = await loginApi(data)
      ctx.commit('updataToken', res.data.token)
      console.log(res)
    },
    async getToken2 (ctx, data) {
      const res = await captchaloginApi(data)
      ctx.commit('updataToken2', res.data.token)
      console.log(res)
    }
  }
}
